package org.zpmis.domain.purchase.vo;

import lombok.Data;
import org.zpmis.domain.purchase.model.Purchase;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
public class PurchaseListVo implements Serializable {
    /**
     * 主键id
     */
    private Long id;

    /**
     * 采购单编号
     */
    private String code;
    /**
     * 采购单名称
     */
    private String name;

    /**
     * 采购类型
     */
    private Integer type;

    /**
     * 采购对应的商品id
     */
    private Long repoId;

    /**
     * 采购数量
     */
    private Long total;

    /**
     * 采购单价
     */
    private BigDecimal price;

    /**
     * 附件（钉钉审批通过单截图）
     */
    private String attachment;

    /**
     * 采购状态 1采购中2已完成3采购失败
     */
    private Integer status;

    /**
     * 采购负责人
     */
    private String chargePerson;

    /**
     * 采购时间
     */
    private String purchaseTime;
    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建人
     */
    private String createPerson;

    /**
     * 修改时间
     */
    private String updateTime;

    public PurchaseListVo(Purchase purchase) {
        this.id = purchase.getId();
        this.code = purchase.getCode();
        this.name = purchase.getName();
        this.type = purchase.getType();
        this.repoId = purchase.getRepoId();
        this.total = purchase.getTotal();
        this.price = purchase.getPrice();
        this.attachment = purchase.getAttachment();
        this.status = purchase.getStatus();
        this.chargePerson = purchase.getChargePerson();
        this.purchaseTime = purchase.getPurchaseTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(purchase.getPurchaseTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.createTime = purchase.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(purchase.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.createId = purchase.getCreateId();
        this.createPerson = purchase.getCreatePerson();
        this.updateTime = purchase.getUpdateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(purchase.getUpdateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}